<?php

require_once dirname(__FILE__).'/../lib/observacion_tesisGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/observacion_tesisGeneratorHelper.class.php';

class observacion_tesisActions extends autoObservacion_tesisActions
{
	
	public function execute($request)
	{
		$tesis_id = $request->getUrlParameter('tesis_id');
		$this->forward404Unless($tesis_id);

		$this->getContext()->getRouting()->setDefaultParameter('tesis_id', $tesis_id);

		return parent::execute($request);
	}

	public function executeIndex(sfWebRequest $request)
	{
		$tesis = TesisTable::getInstance()->getTemaById($request->getParameter('tesis_id'));
		$this->getUser()->setFlash('info', $tesis, false);
		parent::executeIndex($request);
	}

	public function executeNew(sfWebRequest $request)
	{
		$tesis_id = $request->getUrlParameter('tesis_id');
		
		$this->observacion_tesis = new ObservacionTesis();
		$this->observacion_tesis->setTesisId($tesis_id);
		
		$this->form = $this->configuration->getForm($this->observacion_tesis);
	}

	public function executeCreate(sfWebRequest $request)
	{
		parent::executeCreate($request);
		$this->form->getObject()->setTesisId($request->getUrlParameter('tesis_id'));
	}

	public function executeShow(sfWebRequest $request)
	{
		$this->observacion_tesis = Doctrine_Core::getTable('ObservacionTesis')->find($request->getParameter('id'));
		$this->forward404Unless($this->observacion_tesis, 'La observacion no existe');
	}

	protected function buildQuery()
	{
		$query = parent::buildQuery();
		$query->addWhere('tesis_id = ?', $this->getRequest()->getUrlParameter('tesis_id'));
		return $query;
	}

}
